package com.xlh.util;

import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * 分页DTO
 *
 * @author cheer
 */
public class PageDTO<T> {

    private final int pageNum;
    private final int pageSize;
    private final long total;
    private final int pages;
    private final List<T> content;

    @SuppressWarnings("unchecked")
    public PageDTO(PageInfo pageInfo) {
        this.pageNum = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.total = pageInfo.getTotal();
        this.pages = pageInfo.getPages();
        this.content = pageInfo.getList();
    }

    public int getPageNum() {
        return pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public long getTotal() {
        return total;
    }

    public int getPages() {
        return pages;
    }

    public List<T> getContent() {
        return Collections.unmodifiableList(content);
    }

    public boolean hasContent() {
        return CollectionUtils.isNotEmpty(content);
    }
}
